<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>登录</title>
    <link rel="stylesheet" href="css/AllStyle.css" />
    <script src="js/mui.min.js"></script>
    <script type="text/javascript" src="js/common.js" ></script>
    <script type="text/javascript" src="js/data.js" ></script>
    <script type="text/javascript" src="js/tmpl.js" ></script>
    <script type="text/javascript">
		function plusReady(){
			// 设置状态栏背景颜色
			plus.navigator.setStatusBarBackground("#00aafa");
		}
		if(window.plus){
			plusReady();
		}else{
			document.addEventListener("plusready",plusReady,false);
		}
	</script>
</head>
<body style="background-color: #00aafa;">
	<div class="logo"><img width="100%" src="images/logo.png"></div>

	<section>
		<form>
		<div class="LoginBlock">
			<ul>
				<li>
					<p><img src="images/user.png"></p>
					<p><input placeholder="用户名" type="text" name="login-name" value="admin" id="login-name"></p>
				</li>
				<li>
					<p><img src="images/password.png"></p>
					<p><input placeholder="密码" type="password" id="login-pass" value="123456" name="login-pass" onkeypress="if (event.keyCode == 13) { checkForm(); return false;}"></p>
				</li>
			</ul>
			<button type="button" onclick="checkForm()">登录</button>
			<a class="ForgetPassword">忘记密码？</a>
		</div>
		</form>
	</section>
</body>
<script type="text/javascript" src="js/jquery.min.js" ></script>
<script type="text/javascript" src="js/jquery.md5.js" ></script>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript">
	function plusReady(){
		var types = {};
		types[plus.networkinfo.CONNECTION_UNKNOW] = "Unknown connection";
		types[plus.networkinfo.CONNECTION_NONE] = "None connection";
		types[plus.networkinfo.CONNECTION_ETHERNET] = "Ethernet connection";
		types[plus.networkinfo.CONNECTION_WIFI] = "WiFi connection";
		types[plus.networkinfo.CONNECTION_CELL2G] = "Cellular 2G connection";
		types[plus.networkinfo.CONNECTION_CELL3G] = "Cellular 3G connection";
		types[plus.networkinfo.CONNECTION_CELL4G] = "Cellular 4G connection";

		if(types[plus.networkinfo.getCurrentType()] == "None connection"){
			plus.nativeUI.alert( "当前没有网络!", function(){}, "溯源系统", "OK" );
		}else{
			$(function () {
		        var username = $_GET['username'];
		        var password = $_GET['password'];
		        if(!empty(username) && !empty(password)){
		            login(username,password);
		        }
		        var Identity = getIdentity();
		        if(Identity == '代理'){
		//        openUrl('proxy.html');
		        }else if(Identity == '企业'){
		          openUrl('supper.html');
		        }else if(Identity == '网点'){
		          openUrl('website.html');
		        }
		        if (!empty($("#login-name").val())) {
		            // $("#login-name").val(getCookie("login-name"));
		        }
		        window.onload = function () {
		            setInterval(isOnline, 10000);
		        };
		        document.addEventListener('deviceready', onDeviceReady, true);

		        $('#login-pass').on('blur',function(){
			       var  username = $('#login-name').val();
			       var  password = $('#login-pass').val();
			       if (empty(username)||empty(password)) {
			       		$('.LoginBlock button').css({backgroundColor:'#038aca'});
			       }else{
			       		$('.LoginBlock button').css({backgroundColor:'#c2ebff'});
			       }
		        });
		    });
		}
	}
	if(window.plus){
		plusReady();
	}else{
		document.addEventListener("plusready",plusReady,false);
	}


    function checkForm(){
       var  username = $('#login-name').val();
       var  password = $('#login-pass').val();
        login(username,password);
    }
    function login(username,password) {
        if (empty(username)) {
            alertMessage("账户名称不能为空！");
           return false;
        }
        if (empty(password)) {
           alertMessage("密码不能为空！");
           return false;
        }
        var pwd = $.md5(password);
			// openUrl("supper.html");
			// return true;
		let data = {"username": username,"password": password,"isPhone":true};
        $.ajax({//一个Ajax过程
            type: "post", //以post方式与后台沟通
            url: getServerUrl()+"/sys/login", //与此jeecgboot登入接口沟通
            dataType: 'json', //从php返回的值以 JSON方式 解释
			contentType: 'application/json',
            data: JSON.stringify(data),
            success: function (json) {//如果调用php成功
				if(json.code === 200 && json.result.token !== undefined && json.result.token !== ""){
					setCookie("token",json.result.token);
					setCookie("userName",username);
					mui.openWindow({
						url: 'supper.html?workType='+json.result.userInfo.workType,
						id:'supper.html'
					});
				}else{
					alertMessage("账户或用户名错误");
				}
            }
        });
    }

    function onDeviceReady() {

        document.addEventListener("backbutton", onBackKeyDown, false);
    }
    function onBackKeyDown() {
        // Handle the back button
        exitFromApp();
    }

	var showMenu = false;
	mui.plusReady(function() {
	    //首页返回键处理
		//处理逻辑：1秒内，连续两次按返回键，则退出应用；
		var first = null;
		mui.back = function() {
			if (showMenu) {
				closeMenu();
			} else {
				//首次按键，提示‘再按一次退出应用’
				if (!first) {
					first = new Date().getTime();
					mui.toast('再按一次退出应用');
					setTimeout(function() {
						first = null;
					}, 1000);
				} else {
					if (new Date().getTime() - first < 1000) {
						plus.runtime.quit();
					}
				}
			}
		};
	});
</script>
</html>
